home *** CD-ROM | disk | FTP | other *** search
/ Singles Flirt Up Your Life! (German) / Singles Flirt Up Your Life.iso / data1.cab / Statemachine / chairChar.lua < prev    next >
Text File  |  2004-01-29  |  4KB  |  155 lines

  1. -- chair character state machine
  2. beginStateMachine()
  3.     
  4.     onEnter(function(msg)
  5.     
  6.         print("chair character state machine onEnter");
  7.         local chair = retrieveStateObject("chair");
  8.         if (not chair) then chair = getStateObjectFromID(msg.sender); end;        
  9.         storeStateObject("chair", chair);
  10.         
  11.         if (chair) then
  12.             --chair does exist
  13.             if (getParent().isOneActionPointLocked(chair)) then
  14.                 -- action point is locked
  15.                 getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  16.                 sendMsg("emoThink", getParent().walkSO);
  17.                 exitStateMachine();
  18.             else
  19.                 getParent().lockActionPoints(chair);
  20.                 -- check wich side of chair
  21.                 local actionPointName = retrieveData("actionPointName");
  22.                 print(actionPointName);
  23.                 
  24.                 -- coming from left behind
  25.                  if (actionPointName == "sit2") then
  26.                     storeData("mirrorAnims", true);
  27.                 else
  28.                     storeData("mirrorAnims", false);
  29.                 end
  30.                 
  31.                 -- coming from front
  32.                  if (actionPointName == "sit3") then
  33.                     storeData("fromFront", true);
  34.                 else
  35.                     storeData("fromFront", false);
  36.                 end
  37.                 
  38.             end
  39.         else
  40.             -- chair does not exist anymore
  41.             getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  42.             sendMsg("emoThink", getParent().walkSO);
  43.             exitStateMachine();
  44.         end
  45.         
  46.         freeHands(getParent());
  47.     end )
  48.     
  49.     onExit(function(msg)
  50. --        local chair = retrieveStateObject("chair");
  51. --        getParent().unlockActionPoints(chair);
  52. --        removeStateObject("chair");
  53.         
  54.         unlockAll("chair");
  55.     end )
  56.     
  57.     -- sit down on chair
  58.     state("sitDown")
  59.     
  60.         onEnter(function(msg)
  61.         print("sitDown onEnter");
  62.             local chair = retrieveStateObject("chair");
  63.             
  64.             if (retrieveData("fromFront") == true) then
  65.                 setPose("sitdownChairHandsDown");
  66.                 sendDelayedMsgThis("sitSound", 2000);
  67.             else
  68.                 setPose("sitdownChair", retrieveData("mirrorAnims"));
  69.                 chair.startAnimation("ChairSitdown");
  70.                 chair.playSound("Stuhl hinsetzen");
  71.                 -- send a delayed message for sit sound
  72.                 sendDelayedMsgThis("sitSound", 3000);
  73.             end
  74.             
  75.             
  76.         end )
  77.     
  78.         onMsg("end", function(msg)
  79.             setCurrentPosition();
  80.             if testCancel() then
  81.                 setState("standUp");
  82.             else
  83.                 local chair = retrieveStateObject("chair");
  84.                 getParent().startActivity("sit", chair);
  85.                 sendDelayedMsgThis("act", 5000);
  86.                 this.actionComplete();
  87.                 
  88.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  89.                 
  90.                 --notify mission that the character sat on the chair
  91.                 getParent().sendMsg(
  92.                     "sat",
  93.                     getParent().getGameObjectServer().mission, 
  94.                     tostring(chair.getUniqueID()) );
  95.  
  96.             end
  97.         end )    
  98.     
  99.         onMsg("queue", function(msg)
  100.             setState("standUp");
  101.         end )        
  102.     
  103.         onMsg("sitSound", function(msg)
  104.             local chair = retrieveStateObject("chair");
  105.             --chair.playSound("Stuhl setzen");
  106.             makeChairSound(chair, "Down");
  107.         end )    
  108.         
  109.         onMsg("act", function(msg)
  110.             doSomething();
  111.             sendDelayedMsgThis("act", 5000);
  112.         end )
  113.         
  114.         onMsg("testCancel", function(msg)
  115.             if testCancel() or (this.getParent().getActivityQueueCount() > 1) or (not this.getParent().getCurrentActivityGain()) then
  116.                 setState("standUp");
  117.             else
  118.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  119.             end
  120.         end )
  121.         
  122.     -- stand up from chair
  123.     state("standUp")
  124.     
  125.         onEnter(function(msg)
  126.             local chair = retrieveStateObject("chair");
  127.             getParent().stopAllActivities(chair);
  128.         
  129.             if (retrieveData("fromFront") == true) then
  130.                 startAnimation("standupChairHandsDown");
  131.                 sendDelayedMsgThis("upSound", 500);
  132.             else
  133.                 startAnimation("standupChair", retrieveData("mirrorAnims"));
  134.                 chair.startAnimation("ChairSitdown", -1);
  135.                 sendDelayedMsgThis("upSound", 900);
  136.             end
  137.  
  138.         end )
  139.         
  140.         
  141.         onMsg("upSound", function(msg)
  142.             local chair = retrieveStateObject("chair");
  143.             makeChairSound(chair, "Up");
  144.         end )    
  145.     
  146.         onMsg("end", function(msg)
  147.             if (retrieveData("fromFront") == true) then
  148.                 flipPoseDirection();
  149.                 print("flip");
  150.             end;
  151.             setCurrentPosition();
  152.             exitStateMachine();
  153.         end )    
  154.     
  155. endStateMachine()